﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.User", ServerTypeId="{ae70d2a4-ec46-4ed9-9b1e-9d0245754463}")]
    public class User : Principal
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public User(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        internal void InitFromCreationInformation(UserCreationInformation creation)
        {
            if (creation != null)
            {
                base.ObjectData.Properties["Email"] = creation.Email;
                base.ObjectData.Properties["LoginName"] = creation.LoginName;
                base.ObjectData.Properties["Title"] = creation.Title;
            }
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            string str;
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag && (((str = peekedName) != null) && (str == "Email")))
            {
                flag = true;
                reader.ReadName();
                base.ObjectData.Properties["Email"] = reader.ReadString();
            }
            return flag;
        }

        [Remote]
        public void Update()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Update", null);
            base.Context.AddQuery(query);
        }

        [Remote]
        public string Email
        {
            get
            {
                base.CheckUninitializedProperty("Email");
                return (string) base.ObjectData.Properties["Email"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value == null)
                    {
                        throw ClientUtility.CreateArgumentNullException("value");
                    }
                    if ((value != null) && (value.Length > 0xff))
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["Email"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Email", value));
                }
            }
        }
    }
}

